<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>找回密码</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
    <link rel="stylesheet" href="../../js/lay-module/step-lay/step.css" media="all">
    <style>
        .layui-input {
            width: 225px;
        }
    </style>
</head>
<body>
<div class="layuimini-container"  style="height: 720px">
    <div class="layuimini-main">
        <div class="layui-fluid">
            <div class="layui-card">
                <div class="layui-card-body" style="padding-top: 40px;">
                    <div class="layui-carousel" id="stepForm" lay-filter="stepForm" style="margin: 0 auto;">
                        <div carousel-item>
                            <div>
                                <form class="layui-form" style="margin: 0 auto;max-width: 460px;padding-top: 40px;">
                                    <div class="layui-form-item" style="width: 500px">
                                        <label class="layui-form-label">手机号码:</label>
                                        <div class="layui-input-inline">
                                            <input id="phone" name="phone" type="text" class="layui-input" lay-verify="required|phone" required />
                                        </div>
<!--                                        <button id="msgBtn" type="button" style="float: right" class="layui-btn layui-btn-normal">发送验证码</button>-->
                                        <input style="float: right;right: -100px" class="layui-btn layui-btn-normal" type="button" id="sendCodeButton" name="获取验证码" value="获取验证码" />
                                    </div>
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">短信验证码:</label>
                                        <div class="layui-input-block">
                                            <input type="text" id="msgCode" name="msgCode" value="" lay-verify="required|msgCode" lay-verType="msg" class="layui-input" required>
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <div class="layui-input-block">
                                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                            <button style="text-align: center;margin-top: 50px;" class="layui-btn layui-btn-primary" lay-submit lay-filter="formStep">
                                                &emsp;下一步&emsp;
                                            </button>
                                        </div>
                                    </div>
                                </form>
                            </div>
                            <div>
                                <form class="layui-form" style="margin: 0 auto;max-width: 460px;padding-top: 40px;">
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">输入新密码:</label>
                                        <div class="layui-input-block">
                                            <input type="password"  class="layui-input" lay-verify="required"/>

                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">确认新密码:</label>
                                        <div class="layui-input-block">
                                            <input type="password" value="" class="layui-input"lay-verify="required" >
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <div class="layui-input-block"  style="margin-top: 50px;">
                                            <!--                                            <button type="button" class="layui-btn layui-btn-primary pre">上一步</button>-->
                                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                            <button class="layui-btn layui-btn-primary" lay-submit lay-filter="formStep2">
                                                &emsp;完成&emsp;
                                            </button>
                                        </div>
                                    </div>
                                </form>
                            </div>
                            <div>
                                <div style="text-align: center;margin-top: 90px;">
                                    <i class="layui-icon layui-circle"
                                       style="color: white;font-size:30px;font-weight:bold;background: #52C41A;padding: 20px;line-height: 80px;">&#xe605;</i>
                                    <div style="font-size: 24px;color: #333;font-weight: 500;margin-top: 30px;">
                                        重置密码成功
                                    </div>
                                    <!--                                    <div style="font-size: 14px;color: #666;margin-top: 20px;">预计两小时到账</div>-->
                                </div>
                                <div style="text-align: center;margin-top: 50px;">
                                    <button id="clickToLogin" class="layui-btn layui-btn-primary">跳转登录</button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="footer" style="text-align: center">
        ©版权所有 2021-2022 www.personnel.xyz
    </div>
</div>
<script src="../../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="../../js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script src="../../lib/jquery-3.4.1/jquery-3.4.1.min.js"></script>
<script>
    var myCode;
    $("#sendCodeButton").click(function() {
        if (/^1([358][0-9]|4[579]|66|7[0135678]|9[89])[0-9]{8}$/.test($("#phone").val())) {
                $(this).addClass("on");
                var time = 60;
                $(this).attr("disabled", true);
                var timer = setInterval(function() {
                    if (time == 0) {
                        clearInterval(timer);
                        $("#sendCodeButton").attr("disabled", false);
                        $("#sendCodeButton").val("获取验证码");
                        $("#sendCodeButton").removeClass("on");
                    } else {
                        $("#sendCodeButton").val(time + "秒后重新发送...");
                        time--;
                    }
                }, 1000);
                $.ajax({
                    url:"/msgCode/sendCode",         	// 请求路径
                    type:"post",            // 请求的方式，不区分大小写
                    data: {                 // 传递参数的key-value严格区分大小写
                        phone: $("#phone").val(),
                    },
                    success:function(response){
                        if(response.code === 200) {
                            layer.msg("发送成功,请注意查收！")
                        }
                        else {
                            layer.msg(response.msg)
                        }
                        console.log("数据: " + response);
                    },
                    error:function(response){
                        console.log("出错" + response);
                    }
                });
        }else {
            layer.msg('电话号码不正确！',{time:500});
        }
    });
</script>
<script>
    layui.use([ 'form', 'step'], function () {
        var $ = layui.$,
            form = layui.form,
            step = layui.step;

        step.render({
            elem: '#stepForm',
            filter: 'stepForm',
            width: '100%', //设置容器宽度
            stepWidth: '750px',
            height: '500px',
            stepItems: [{
                title: '短信验证'
            }, {
                title: '重置密码'
            }, {
                title: '完成'
            }]
        });

        form.verify({
            msgCode: function(value) { //value：表单的值、item：表单的DOM对象
               //debugger;
               // if ("1234" === value) {
               //      return '验证码错误';
               //  }
                console.log(myCode)
               if (myCode !== value) {
                    return '验证码错误';
                }
            },
        });
        form.on('submit(formStep)', function (data) {

            step.next('#stepForm');
            return false;
        });


        form.on('submit(formStep2)', function (data) {
            step.next('#stepForm');
            return false;
        });

        $('.pre').click(function () {
            step.pre('#stepForm');
        });

        $('.next').click(function () {
            step.next('#stepForm');
        });

        $('#clickToLogin').click(function () {
            window.location.href = "../../login.html";
        });
    })
</script>

</body>
</html>